<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for PKCS5 RSA key reader 'keyutil.js' for RSA public key</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<!-- script type="text/javascript" src="qunit.js" /script -->
<!-- link rel="stylesheet" href="qunit.css" type="text/css" media="screen" -->
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" type="text/css" media="screen"/>

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>


<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// _test/z2.pub
var z2PubPem = "" + 
"-----BEGIN PUBLIC KEY-----\n" + 
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOtpGHibL8Ue+MXPPufkcrNES40rCT5L\n" + 
"RIU9MjTZ8/7owG5bAsiFA9Xxh3uZK1T5QA64jNJVbp2ojHAtNyWPuwsCAwEAAQ==\n" + 
"-----END PUBLIC KEY-----\n";

var z2PubHex = "305c300d06092a864886f70d0101010500034b003048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001";

var z2RawPubHex = "3048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001";

// _gitpg/jsrsasign/test/eckey/k1.pub.der
var k1PubPem = "" +
"-----BEGIN PUBLIC KEY-----\n" + 
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjT\n" + 
"CLQeb042TjiMJxG+9DLFmRSMlBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==\n" + 
"-----END PUBLIC KEY-----\n";

var k1PubHex = "3059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425";

// ======= TEST ===================================================================================

test("getKey(z2PubHex) z2", function() {
  var k = KEYUTIL.getKey(z2PubHex, null, "pkcs8pub");
  equal(k.n.toString(16), "eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", "rsaKey.n");
  equal(k.e.toString(16), "10001", "rsaKey.e");
});

test("getKey(z2PubPem) z2", function() {
  var k = KEYUTIL.getKey(z2PubPem);
  equal(k.n.toString(16), "eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", "rsaKey.n");
  equal(k.e.toString(16), "10001", "rsaKey.e");
});

test("parsePublicPKCS8PEM z2(RSA)", function() {
  var r = KEYUTIL.parsePublicPKCS8Hex(z2PubHex);
  expect(3);
  equal(r.algoid, "2a864886f70d010101", "algoid");
  equal(r.algparam, null, "algparam");
  equal(r.key, "3048024100eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b0203010001");
});

test("parsePublicPKCS8PEM k1(EC)", function() {
  var r = KEYUTIL.parsePublicPKCS8Hex(k1PubHex);
  expect(3);
  equal(r.algoid, "2a8648ce3d0201", "algoid");
  equal(r.algparam, "2a8648ce3d030107", "algparam");
  equal(r.key, "04a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425", "key");
});

test("parsePublicRawRSAKeyHex key of z2(RSA)", function() {
  var r = KEYUTIL.parsePublicRawRSAKeyHex(z2RawPubHex);
  expect(2);
  equal(r.n, "00eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", "n");
  equal(r.e, "010001", "e");
});

test("getKey(z2PubPem) z2(RSA)", function() {
  var key = KEYUTIL.getKey(z2PubPem);
  equal(key.type, "RSA", "type");
  equal(key.n.compareTo(new BigInteger("00eb6918789b2fc51ef8c5cf3ee7e472b3444b8d2b093e4b44853d3234d9f3fee8c06e5b02c88503d5f1877b992b54f9400eb88cd2556e9da88c702d37258fbb0b", 16)), 0, "n");
  equal(key.e, 65537, "e(65537)");
});

test("getKey(k1PubPem) k1(EC)", function() {
  var key = KEYUTIL.getKey(k1PubPem);
  equal(key.type, "EC", "type");
  equal(key.curveName, "secp256r1", "curveName");
  equal(key.pubKeyHex, "04a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425", "pubKeyHex");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
QUnit for 
<a href="qunit-do-keyutil.html">keyutil</a> | 
<a href="qunit-do-keyutil-eprv.html">keyutil-eprv</a> | 
<a href="qunit-do-keyutil-pub.html">keyutil-pub</a> | 
</body>
</html>


